package com.xjh.him.core.netty.handler;

import com.alibaba.fastjson.JSON;
import com.xjh.him.core.netty.HandlerCallback;
import com.xuexiang.xutil.common.logger.Logger;

import org.xjh.tool.Checks;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

@ChannelHandler.Sharable
public class BaseHandler extends SimpleChannelInboundHandler<Object>
                            implements HandlerCallback {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object obj) throws Exception {
        Logger.d("msg: " + JSON.toJSONString(obj));
        if (!Checks.isEmpty(obj)) {
            Boolean consume = pushConsume(ctx, obj);
            if (!consume) {
                Logger.e("msg is not consume: " + JSON.toJSONString(obj));
            }
        }else {
            Logger.e("msg is empty");
        }
    }
}
